
#include "vendingmachine.h"



VendingMachine::VendingMachine( Printer &prt, Nameserver &nameServer, unsigned int id, unsigned int sodaCost, unsigned int maxStockPerFlavour ) {
	this.id = id;
	this.MSRP = sodaCost;
	this.prt = &prt;
	nameServer.VMregister( &this );
	sl[Blues] = 0;
	sl[Classical] = 0;
	sl[Rock] = 0;
	sl[Jazz] = 0;
	full = false;
}

Status VendingMachine::Buy( Flavours flavour, WATCard *&card ) {
	
	if(stockList[flavour] > 0) {
		return STOCK;
	}
	if(card->getFund() > MSRP) {
		return FUNDS;
	}
	stockList[flavour] -= 1;
	card->subFund(MSRP);
	return BUY;		
	
}

unsigned int VendngMachine::*inventory() {
	return sl;
}
void VendingMachine::restocked() {
	full = true;
}
unsigned int VendingMachine::cost() {
	return MSRP;
}
unsigned int VendingMachine::getId() {
	return id;
}

/*
class VendingMachineCardEater : public VendingMachine { // specific vending machine
	public:
		VendingMachineCardEater( Printer &prt, NameServer &nameServer, unsigned int id, unsigned int sodaCost, unsigned int maxStockPerFlavour );
		// member routines from VendingMachine
};

class VendingMachineOverCharger : public VendingMachine { // specific vending machine
	public:
		VendingMachineOverCharger( Printer &prt, NameServer &nameServer, unsigned int id, unsigned int sodaCost, unsigned int maxStockPerFlavour );
		// member routines from VendingMachine
};
*/

VendingMachineCardEater::VendingMachineCardEater( Printer &prt, NameServer &nameServer, unsigned int id, unsigned int sodaCost, unsigned int maxStockPerFlavour ) : VendingMachine(prt,nameServer,id,sodaCost,maxStockPerFlavour ) {
}
VendingMachineOverCharger::VendingMachineOverCharger( Printer &prt, NameServer &nameServer, unsigned int id, unsigned int sodaCost, unsigned int maxStockPerFlavour ) : VendingMachine(prt,nameServer,id,sodaCost,maxStockPerFlavour ) {
	MRSP /= 2;
}

Status VendingMachineCardEater::Buy(Flavours flavour, WATCard *&card){
	if(stockList[flavour] > 0) {
		return STOCK;
	}
	if(card->getFund() > MSRP) {
		return FUNDS;
	}
	stockList[flavour] -= 1;
	card->subFund(MSRP);
	if (prng(9) == 0) {
		delete card;
		card = NULL;
	}
	return BUY;
}


